#include "../source/address.h"
#include "../source/log.h"
#include <iostream>

void testLookUp()
{
    std::vector<Address::ptr> result;
    Address::Lookup(result, "www.baidu.com:ftp", AF_INET);

    if(!result.empty())
    {
        for(const auto&t : result)
        {
            // std::cout << t->toString() << std::endl;
            log_info("{}", t->toString());
        }
    }
}

void testGetInterface()
{
    std::multimap<std::string, std::pair<Address::ptr, uint32_t>> result;
    auto ret = Address::GetInterfaceAddresses(result, AF_INET6);
    if(!ret)
    {
        log_error("GetInterfaceAddresses error");
    }

    for(const auto&t: result)
    {
        log_info("name:{}, ip:{}, number:{}", 
            t.first, t.second.first->toString(), t.second.second);
    }

}

void testIPv4()
{
    // auto addr = IPAddress::Create("www.baidu.com");
    auto addr = IPAddress::Create("192.168.1.123");
    if(addr)
    {
        log_info("{}, broadcast:{}, netword:{}, subnet:{}",
            addr->toString(), addr->broadcastAddress(24)->toString(),
            addr->networdAddress(24)->toString(), addr->subnetMask(24)->toString());
    }
}

int main(void)
{
    // testLookUp();
    // testGetInterface();
    testIPv4();

    return 0;
}